﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CYTS.Aoyou.Framework.Context
{
    /// <summary>
    /// 上下文工厂
    /// </summary>
    public class ContextFactory
    {
        private static IContextHandler _ContextHandler = null;

        /// <summary>
        /// 注册上下文句柄
        /// </summary>
        /// <param name="handler"></param>
        public static void RegisterContextHandler(IContextHandler handler)
        {
            _ContextHandler = handler;
        }

        /// <summary>
        /// 获取当前上下文
        /// </summary>
        /// <returns></returns>
        public static WebContext GetContext()
        {
            if (_ContextHandler != null)
            {
                return _ContextHandler.GetContext();
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 设置当前上下文
        /// </summary>
        public static void SetContext(WebContext context)
        {
            if (_ContextHandler == null)
            {
                _ContextHandler = new DefaultContextHandler();
            }

            _ContextHandler.SetContext(context);
        }
    }
}
